<?php

//uses singlton design patttern
class DatabaseConnection {

    private static $dsn = 'mysql:host=localhost;dbname=mcs5303';
    private static $username = 'admin';
    private static $password = 'admin';
    private static $dbh = null;

    private function __construct() {
    }

      /**
     * <p>Returns PDO database handler object.</p>
       * implements singlton design pattern.
     * @param void
     * @return PDO
     * <b>PDO object</b>
     */
    public static function getDB() {
        if (!isset(self::$dbh)) {
            try {
                self::$dbh = new PDO(self::$dsn, self::$username, self::$password);
                return self::$dbh;
            } catch (PDOException $e) {
                echo "Connection error: " . $e->getMessage();
                exit();
            }
        } else {
            return self::$dbh;
        }
    }

}

?>